<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="Author" content="TanShenghu">
    <title>cookie 组件</title>
    <style>
    *{margin:0;padding:0;}
    button{border:1px solid #ccc;padding:10px 25px;cursor:pointer;}
    </style>
    <script src="http://www.tanshenghu.com/static/js/sea.js"></script>
    <script>
    seajs.config({
      paths: {
        'tanshenghu': 'http://www.tanshenghu.com/static/js',
        'widget': 'http://www.tanshenghu.com/widget'
      },    
      alias: {
        '$': 'tanshenghu/$',
        'cookie': 'widget/cookie/1.0.0/cookie'
      }
    });
    </script>
</head>
<body>
    页面背影颜色：<select><option value="red">红色</option><option value="green">绿色</option><option value="yellow">黄色</option><option value="blue">蓝色</option></select><button>设置cookie</button><button>获取cookie</button><button>删除cookie</button>
    <script>
    seajs.use('cookie', function( cookie ){
        
        jQuery('button:first').on('click', function(){
            
            cookie.setCookie( 'color', jQuery(this).prev().val(), 30 );
            
        }).next()
        .on('click', function(){
            
            alert( cookie.getCookie( 'color' ) );
            
        }).next()
        .on('click', function(){
            
            cookie.delCookie( 'color' );
            
        })
        
        document.body.style.backgroundColor = cookie.getCookie( 'color' )||'white';
        
    });
    </script>
</body>
</html>